package com.renjibo.sharkerwave.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.renjibo.sharkerwave.R;
import com.renjibo.sharkerwave.models.CourseDetail;
import com.renjibo.sharkerwave.network.SharkerParams;
import com.renjibo.sharkerwave.utils.ShowHideTop;

import org.xutils.common.Callback;
import org.xutils.x;

/**
 * 我的课程界面
 */
public class CourseFragment extends BaseFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;
    private TextView course_textView;


    public CourseFragment() {
    }


    public static CourseFragment newInstance(String param1, String param2) {
        CourseFragment fragment = new CourseFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
        ShowHideTop.setWindow(getActivity(),false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        detailCourse();
    }

    //请求网络
    void detailCourse(){
        SharkerParams sharkerParams=new SharkerParams("list_my_course");
        sharkerParams.addBodyParameter("page_size",20+"");
        sharkerParams.addBodyParameter("page_index",1+"");
        x.http().post(sharkerParams, new Callback.CommonCallback<CourseDetail>() {

            @Override
            public void onSuccess(CourseDetail result) {
                Log.d("zzz","我的课程:"+result.toString());
                course_textView.setText("亲，未登录哦！");
//                Toast.makeText(getActivity(),"s:"+result.toString(),Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_course, container, false);
        course_textView = (TextView) view.findViewById(R.id.course_textView);
        return view;
    }

}
